package com.yang.studentsapp.model;


import com.android.volley.Request;
import com.google.gson.reflect.TypeToken;
import com.yang.studentsapp.Grid;
import com.yang.studentsapp.ProtocolKey;
import com.yang.studentsapp.UrlConstant;
import com.yang.studentsapp.utils.MyRequest;
import com.yang.studentsapp.utils.RQManager;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Created by MVPHelper on 2016/10/10
*/

public class SettingModeGrid extends SettingModel{
    String mPicAddress = UrlConstant.BaseUrl + UrlConstant.GetSchoolSlider;

    String mNewsAddress = UrlConstant.BaseUrl + UrlConstant.GetSchoolSimgnewsList;

    public SettingModeGrid(IAction iAction) {
        super(iAction);
    }
//    public void getBanners(final IActionSuccess<List<SchoolBanner>> success){
//        mIAction.start("正在加载");
//        Map<String, String> params = new HashMap<>();
//        params.put(ProtocolKey.SIGNITURE, ProtocolKey.APPSECRET);
//        MyRequest<List<SchoolBanner>> myRequest = new MyRequest<>(
//                Request.Method.POST, mPicAddress, params,
//                new TypeToken<List<SchoolBanner>>() {},
//                new MyRequest.IRequest<List<SchoolBanner>>() {
//                    @Override
//                    public void fail(String msg) {
//                        mIAction.fail(msg);
//                    }
//
//                    @Override
//                    public void success(List<Grid> schoolBanners) {
//                        success.success(schoolBanners);
//                    }
//
//                    @Override
//                    public void error(String msg) {
//                        mIAction.error(msg);
//                    }
//                }
//        );
//        RQManager.queue().add(myRequest);
//    }

    public void getNews(final IActionSuccess<List<Grid>> success){
        iAction.start("正在加载");
        Map<String, String> params = new HashMap<>();
        params.put(ProtocolKey.SIGNITURE, ProtocolKey.APPSECRET);
        MyRequest<List<Grid>> myRequest = new MyRequest<>(
                Request.Method.POST, mNewsAddress, params,
                new TypeToken<List<Grid>>() {
                },
                new MyRequest.IRequest<List<Grid>>() {
                    @Override
                    public void fail(String msg) {
                        iAction.fail(msg);
                    }

                    @Override
                    public void success(List<Grid> schoolNewses) {
                        success.succes(schoolNewses);
                    }

                    @Override
                    public void error(String msg) {
                        iAction.error(msg);
                    }
                }
        );
        RQManager.queue().add(myRequest);
    }

}